//
//  CardPackageView.m
//  MyWallet
//
//  Created by 小肥羊 on 15/7/15.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "CardPackageView.h"

@implementation CardPackageView

#pragma mark - 初始化
- (id)init
{
    NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"CardPackageView" owner:nil options:nil];
    self = [nibs lastObject];
    if (self) {
        self.card1.delegate = self;
        self.card2.delegate = self;
        self.card3.delegate = self;
        self.card4.delegate = self;
        self.card5.delegate = self;
        self.card6.delegate = self;
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"CardPackageView" owner:nil options:nil];
    self = [nibs lastObject];
    if (self) {
        self.frame = frame;
        self.card1.delegate = self;
        self.card2.delegate = self;
        self.card3.delegate = self;
        self.card4.delegate = self;
        self.card5.delegate = self;
        self.card6.delegate = self;
    } else {
        self = [super initWithFrame:frame];
    }
    return self;
}


#pragma mark - 卡代理
- (void)saveMoney:(CardView *)cardView
{
    if (self.delegate) {
        [self.delegate saveMoney:self CardView:cardView AtIndex:[self findCardInteger:cardView]];
    }
}

- (void)drawMoney:(CardView *)cardView
{
    if (self.delegate) {
        [self.delegate drawMoney:self CardView:cardView AtIndex:[self findCardInteger:cardView]];
    }
}

- (void)checkCard:(CardView *)cardView
{
    if (self.delegate) {
        [self.delegate checkCard:self CardView:cardView AtIndex:[self findCardInteger:cardView]];
    }
}

- (void)activationCard:(CardView *)cardView
{
    if (self.delegate) {
        [self.delegate activationCard:self CardView:cardView AtIndex:[self findCardInteger:cardView]];
    }
}

- (void)cancellationCard:(CardView *)cardView
{
    if (self.delegate) {
        [self.delegate cancellationCard:self CardView:cardView AtIndex:[self findCardInteger:cardView]];
    }
}

#pragma mark - 方法
- (NSInteger)findCardInteger:(CardView *)cardView
{
    if ([cardView isEqual:self.card1]) {
        return 1;
    } else if ([cardView isEqual:self.card2]) {
        return 2;
    } else if ([cardView isEqual:self.card3]) {
        return 3;
    } else if ([cardView isEqual:self.card4]) {
        return 4;
    } else if ([cardView isEqual:self.card5]) {
        return 5;
    } else if ([cardView isEqual:self.card6]) {
        return 6;
    }
    return 0;
}

#pragma mark - 公共方法
- (void)upCardPackage:(TotalAssets *)totalAssets
{
    [self.card1 upCard:totalAssets.card1];
    [self.card2 upCard:totalAssets.card2];
    [self.card3 upCard:totalAssets.card3];
    [self.card4 upCard:totalAssets.card4];
    [self.card5 upCard:totalAssets.card5];
    [self.card6 upCard:totalAssets.card6];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
